package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class TimeAspect {

    @Around("execution(* com.itheima.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //1.开始时间
        long start = System.currentTimeMillis();
        //2.执行原方法
        Object result = pjp.proceed();
        //3.结束时间
        long end = System.currentTimeMillis();

        //日志
        log.info(pjp.getSignature().getName() + " 方法执行了：{} ms", end - start);

        return result;
    }
}
